package cn.yeziji.forum.controller;

import cn.yeziji.forum.common.ForumResult;
import cn.yeziji.forum.dao.intf.ForumUserQaDao;
import cn.yeziji.forum.dto.qa.UserQaDTO;
import cn.yeziji.forum.utils.ForumResultUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 论坛用户操作问题或答案
 *
 * @author gzkemays
 * @since 2022/11/15 2:38 PM
 */
@RestController
@RequestMapping("/qa")
public class ForumUserQaController {
  @Resource ForumUserQaDao qaDao;

  @PostMapping("/action")
  public ForumResult action(@Valid @RequestBody UserQaDTO dto) {
    Integer mode = dto.getMode();
    if (mode == 0) {
      qaDao.userCollectionQuestion(dto.getId());
    } else {
      qaDao.userKudosAnswer(dto.getId());
    }
    return ForumResultUtils.ok();
  }
}
